﻿using Common.Helpers;
using System;
using System.Globalization;
using System.Windows.Data;

namespace NxChatQQ.Converters
{
    public class TimeSendConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {

            DateTime inputDateTime = (DateTime)value;
            DateTime now = DateTime.Now;
            TimeSpan timeDifference = now - inputDateTime;

            if (timeDifference.TotalDays < 1)
            {
                // 小于1天，返回 "HH:mm:ss"  
                return inputDateTime.ToString("HH:mm");
            }
            else if (timeDifference.TotalDays < 2)
            {
                // 小于2天，返回 "昨天 HH:mm"  
                return "昨天 " + inputDateTime.ToString("HH:mm");
            }
            else if (DateUtil.IsSameWeek(inputDateTime, now))
            {
                // 在本周内，返回 "星期N HH:mm"  
                return DateUtil.GetChineseDayOfWeek(inputDateTime) + " " + inputDateTime.ToString("HH:mm");
            }
            else
            {
                // 其他情况，返回 "yyyy/MM/dd HH:mm"  
                return inputDateTime.ToString("yyyy/MM/dd HH:mm");
            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }
}
